export const toast = (param) => {
  let options = {
    title: '数据加载中',
    icon: 'none',
    mask: true,
    duration: 3000
  }

  if (typeof param === 'string') {
    options.title = param
  } else if (typeof param === 'object') {
    options = { ...options, ...param }
  }
  wx.showToast(options)
}

export const modal = (options = {}) => {
  return new Promise((resolve) => {
    const defaultOpt = {
      title: '提示',
      content: '您确定执行该操作吗?',
      confirmColor: '#f3514f'
    }

    const opts = Object.assign({}, defaultOpt, options)

    wx.showModal({
      ...opts,
      complete({ confirm, cancel }) {
        confirm && resolve(true)
        cancel && resolve(false)
      }
    })
  })
}

wx.toast = toast
wx.modal = modal
